package com.example.demo.controller;

import com.example.demo.util.OSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * 上传测试类
 */
@RestController
@RequestMapping("/oss")
@Slf4j
public class FileController {
    @RequestMapping("/file")
    public String uploadUrl(@RequestParam("file") MultipartFile file){
        String url = "";
        try {
            log.info("开始上传--------------");
            InputStream inputStream = file.getInputStream();
            InputStream input = inputStream;

            InputStream input1 = input;
            url = OSSUtil.uploadAliyun(input1,file.getOriginalFilename());
            log.info("上传结束-------------");
        }catch (Exception e) {
            e.printStackTrace();
        }
        return url;
    }
}
